
Type CalCoreAnimation

	Field m_listCallbacks:CalCallbackRecord[]
	Field m_duration:Float
	Field m_listCoreTrack:CalCoreTrack[]
	Field m_name:String
	Field m_filename:String
	
	
	Method New()
	
		m_listCallbacks = New CalCallbackRecord[0]
		m_duration = 0
		m_listCoreTrack = New CalCoreTrack[0]
		m_name = "Animation"
		m_filename = ""
	End Method
	
	Method addCoreTrack:Byte(coreTrack:CalCoreTrack)
		Local tsize:Int = m_listCoreTrack.length
		m_listCoreTrack = m_listCoreTrack[..tsize+1]
		m_listCoreTrack[tsize] = coreTrack
		Return True
		
	End Method
	
	Method getCoreTrack:CalCoreTrack(coreBoneId:Int)
		For Local iCoreTrack:Int = 0 To m_listCoreTrack.length-1
			' get the core track
			Local coreTrack:CalCoreTrack = m_listCoreTrack[iCoreTrack]
	
			' check if we found the matching core bone
			If coreTrack.getCoreBoneId() = coreBoneId Then
				Return coreTrack
			EndIf
		Next
	
		' no match found
		Return Null		
	End Method


	Method getDuration:Float()
		Return m_duration
	End Method

	Method setDuration(duration:Float)
		m_duration = duration
	End Method
	
	Method scale(factor:Float)
		For Local iCoreTrack:Int = 0 To m_listCoreTrack.length-1
			m_listCoreTrack[iCoreTrack].scale(factor)
		Next		
	End Method
	
	Method setFilename(filename:String)
		m_filename = filename
	End Method
	
	Method getFilename:String()
		Return m_filename
	End Method
	
	Method setName(name:String)
		m_name = name
	End Method
	
	Method getName:String()
		Return m_name
	End Method
	
	Method registerCallback(callback:CalAnimationCallback, min_interval:Float)
		Local record:CalCallbackRecord = New CalCallbackRecord
		record.callback = callback
		record.min_interval = min_interval
		Local csize:Int = m_listCallbacks.length
		m_listCallbacks = m_listCallbacks[..csize+1]'push(record)	
		m_listCallbacks[csize] = record	
	End Method
	
	Method removeCallback(callback:CalAnimationCallback)
		Local cbr:CalCallbackRecord[] = New CalCallbackRecord[m_listCallbacks.length-1]
		Local pos:Int = 0
		For Local i:Int = 0 To m_listCallbacks.length-1
			If m_listCallbacks[i].callback <> callback Then
				cbr[pos] = m_listCallbacks[i]
				pos=pos+1
			EndIf
		Next
		m_listCallbacks = cbr
			
	End Method
	
	Method getCallbackList:CalCallbackRecord[]()
		Return m_listCallbacks
	End Method
	
	Method getTrackCount:Int()
		Return m_listCoreTrack.length
	End Method
	
	Method getListCoreTrack:CalCoreTrack[]()
		Return m_listCoreTrack
	End Method
	
	Method getTotalNumberOfKeyframes:Int()
		Local nbKeys:Int = 0
		For Local iCoreTrack:Int = 0 To m_listCoreTrack.length-1
			Local coreTrack:CalCoreTrack = m_listCoreTrack[iCoreTrack]
			nbKeys = nbKeys+coreTrack.getCoreKeyframeCount()
		Next
	
		Return nbKeys		
	End Method
	
	
End Type




Type CalCallbackRecord
	
	Field callback:CalAnimationCallback
	Field min_interval:Float
	
	Method New()
		callback = New CalAnimationCallback
		min_interval = 0
	End Method
	
	Function FromCallback:CalCallbackRecord(cac:CalAnimationCallback,minint:Float)
		Local c:CalCallbackRecord = New CalCallbackRecord
		c.callback = cac
		c.min_interval = minint	
		Return c
	End Function
	
	
End Type
